package com.naszetatry.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import com.naszetatry.beans.User;
import com.naszetatry.login.LValidation;
import com.naszetatry.registration.RValidation;

/**
 * 
 * @author Maciej Koch
 * Kontroler rejestracji
 */
public class RegistrationController {
	
	private static final String registeredValidation = "validation";
	private static final String registeredUser = "user";
	private static final String passwordChange = "pc";
	
	/**
	 * Pobiera dane uzytkownika, ktory bierze udzial w rejestracji.
	 * Potrzebne do walidacji danych.
	 * @param request
	 * @return
	 * Uzytkownika
	 */
	public static User getUser(HttpServletRequest request) {
		User user = (User)request.getAttribute(registeredUser);
		if(user != null)
			return user;
		return new User();
	}
	/**
	 * Pobiera liste bledow
	 * @param request
	 * @return
	 * lista bledow
	 */
	public static RValidation getValidation(HttpServletRequest request) {
		RValidation validation = (RValidation)request.getAttribute(registeredValidation);
		if(validation != null)
			return validation;
		return new RValidation();
	}
	/**
	 * Ustawia rejestrujacego sie uzytkownika
	 * @param request
	 * @param user
	 * rejestrujacy sie uzytkownik
	 * 
	 */
	public static void setRegisteredUser(HttpServletRequest request, User user) {
		request.setAttribute(registeredUser, user);
	}
	/**
	 * Ustawia liste bledow przy rejestracji
	 * @param request
	 * @param validation
	 * lista bledow
	 */
	public static void setValidation(HttpServletRequest request, RValidation validation) {
		request.setAttribute(registeredValidation, validation);
	}
	/**
	 * Ustawia liste bledow w procesie zmiany hasla
	 * @param request
	 * @param validation
	 * lista bledow
	 */
	public static void setPasswordChangeValidation(HttpServletRequest request, RValidation validation) {
		request.setAttribute(passwordChange, validation);
	}
	/**
	 * Pobiera liste bledow w procesie zmiany hasla
	 * @param request
	 * @return
	 * lista bledow
	 */
	public static RValidation getPasswordChangeValidation(HttpServletRequest request) {
		RValidation validation = (RValidation)request.getAttribute(passwordChange);
		if(validation != null)
			return validation;
		return new RValidation();
	}

	
}
